<?php
$file_suffix = "nab";
$fp        = $_SERVER['DOCUMENT_ROOT']."nabServer/data/"; 
//==========================================
function readCurrentValue($file)
//==========================================
{    
  if(!file_exists($file))
    {
      return("-");;
    }

  $in = fopen($file,"r");
  if($in)
    {
      $row = fgets($in);
    }  
  fclose($in);
  return($row);
}

//=========================================
$id  = $_GET['id'];

$s_day    = date('d');
$s_month  = date('m');
$s_year   = date('Y');

  echo("Device id: $id | ");

$value = readCurrentValue($fp."time-$id".".".$file_suffix);
echo("$value <br>");
$pnow = readCurrentValue($fp."pow-$id".".".$file_suffix);


// Accumulated consumtion day
$ftemp = 'kwh-'.$id.'-'.$s_year.'-'.$s_month.'-'.$s_day.".".$file_suffix; 
$accDay = readCurrentValue($fp.$ftemp);
$accDay = $accDay/1000;
echo("Accumulated kWh per day: $accDay ");
// Accumulated consumtion month
//$ftemp = 'kwh-'.$id.'-'.$s_year.'-'.$s_month.".bess"; 
//$accMonth = readCurrentValue($ftemp);
//$accMonth = $accMonth/1000;

// Accumulated consumtion year
//$ftemp = 'kwh-'.$id.'-'.$s_year.".bess"; 
//$accYear = readCurrentValue($ftemp);
//$accYear = $accYear/1000;

echo("<br>
	Current Power
	 $pnow Watts
");
//showFileContent("graph-$id.bess");
//showFileContent("consumer-$id.bess");
//echo("<h3>kWh Today: $accDay  Month: $accMonth  Year: $accYear</h3>");

?>
